package cn.zyzpp.controller.exception;

import org.apache.shiro.authz.UnauthenticatedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by yster@foxmail.com 2018/5/27/027 21:51
 */
@ControllerAdvice
public class ExceptionController {
    private String tip = "tip";
    private String message = null;

    @ExceptionHandler(Exception.class)
    public String handle(Exception e, HttpServletRequest request){
        message = "好干净的页面啊，什么都没有的样子";
        if (e instanceof NoHandlerFoundException) {//404

        }
        if (e instanceof UnauthenticatedException){//shiro权限不足
            message = "权限不足以访问此页面，尝试登录下";
        }
        request.setAttribute(tip,message);
        return "pages/404";
    }

}
